package com.nikitova.craps3d.view 
{
	import jiglib.physics.RigidBody;

	import com.carlcalderon.arthropod.Debug;
	import com.nikitova.craps3d.model.GameConfigProxy;
	import com.nikitova.craps3d.model.MaterialsProxy;
	import com.nikitova.craps3d.model.ModelsProxy;
	import com.nikitova.craps3d.view.*;
	import com.nikitova.craps3d.view.components.game3d.TableBorder3D;

	import org.puremvc.as3.multicore.interfaces.*;
	import org.puremvc.as3.multicore.patterns.mediator.*;
	import org.puremvc.as3.multicore.utilities.startupmanager.model.StartupMonitorProxy;

	/**
	 * @author schranz
	 */
	public class TableBorderMediator extends Mediator 
	{
		static public const NAME        : String = "TableBorderMediator";
		
		private var __gameView3DMediator : GameView3DMediator;
		private var __gameConfigProxy    : GameConfigProxy;
		private var __materialsProxy     : MaterialsProxy;
		private var __modelsProxy     	 : ModelsProxy;

		public function TableBorderMediator(component : TableBorder3D, name : String = NAME)
		{
			super(name, component);
		}

		override public function onRegister() : void
		{
			__gameView3DMediator = facade.retrieveMediator(GameView3DMediator.NAME) as GameView3DMediator;
			__gameConfigProxy    = facade.retrieveProxy(GameConfigProxy.NAME) as GameConfigProxy;
			__materialsProxy     = facade.retrieveProxy(MaterialsProxy.NAME) as MaterialsProxy;
			__modelsProxy    	 = facade.retrieveProxy(ModelsProxy.NAME) as ModelsProxy;
			
		}

		override public function listNotificationInterests() : Array  
		{
			return [
						StartupMonitorProxy.LOADING_COMPLETE,
					];
		}

		override public function handleNotification( note : INotification ) : void
		{
			switch ( note.getName()) 
			{
				case StartupMonitorProxy.LOADING_COMPLETE:
					createTableBorder();
					Debug.log("TableLayerIndex: "+component.layerIndex);
				break;
				
				
			}
		}

		public function createTableBorder() : void
		{
			var table:TableBorder3D = new TableBorder3D(__gameView3DMediator.component.tableLayer,__gameView3DMediator.component.physics,__gameView3DMediator.component.light,__modelsProxy.getModelVOById(0).dae,310,546,84);
			setViewComponent(table);
			component.createTable();
			__gameView3DMediator.addBody(RigidBody(table.rigidBody),__gameView3DMediator.component.tableLayer);
		}



		public function get component() : TableBorder3D
		{
			return viewComponent as TableBorder3D;
		}

	}
}
